Add private _asyncioEventLoop module#19816
Merged
seanbudd merged 2 commits intonvaccess:masterfrom Mar 23, 2026
Merged
Conversation
…round thread Split from nvaccess#19122. Provides initialize/terminate lifecycle and runCoroutine/runCoroutineSync helpers for scheduling async work from synchronous code. Wired into core startup/shutdown. Includes 6 unit tests.
cb5ead6 to
13f0d34
Compare
seanbudd
reviewed
Mar 20, 2026
Member
seanbudd
left a comment
There was a problem hiding this comment.
Thanks - all the code here looks good, just needs a slight restructure
… changes entry - Convert _asyncioEventLoop.py to _asyncioEventLoop/ package - __init__.py exposes only initialize() and terminate() - utils.py contains runCoroutine() and runCoroutineSync() - Shared mutable state (eventLoop, asyncioThread) in _state.py - Use triple-quoted docstrings for module-level variable annotations - Move changes.md entry to correct position in developer changes list - Update tests to import from utils module directly
0d1bf04 to
a979fa0
Compare
seanbudd
approved these changes
Mar 23, 2026
Member
Contributor
Author
|
@seanbudd Ah, sorry, forgot to include those, will do |
Contributor
Author
|
@seanbudd After closer inspection, the tests in this PR seem to be complete and match the asyncio tests from the previous PR. Are there specific tests you want to see added for the event loop/asyncio code? Regarding the BLE related tests, I'll do a PR for those as discussed before. |
Member
|
Ooops yes my mistake re-checking the diff. Thanks |
5 tasks
12 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to issue number:
N/A. This is a follow-up from #19122 (DotPad BLE support), splitting out the asyncio event loop module as requested during review.
Summary of the issue:
NVDA currently has no built-in way to run asyncio coroutines. Components that need async functionality (e.g. BLE communication) require a managed asyncio event loop running on a background thread.
Description of user facing changes:
N/A. This is a developer-facing module only.
Description of developer facing changes:
Added a private
_asyncioEventLoopmodule that provides:initialize()/terminate()— lifecycle management, wired into NVDA core startup/shutdownrunCoroutine(coro)— schedule a coroutine on the event loop (fire-and-forget)runCoroutineSync(coro, timeout)— schedule a coroutine and block until completionThe module is prefixed with an underscore to keep it internal to NVDA core and not part of the public add-on API.
Description of development approach:
The asyncio event loop runs on a daemon thread, started during NVDA initialization (after
appModuleHandler) and terminated during shutdown (afterhwIo). Theterminate()function cancels all pending tasks before stopping the loop.runCoroutineSyncwrapsasyncio.run_coroutine_threadsafewith optional timeout support and convertsasyncio.TimeoutErrorto the built-inTimeoutErrorfor a cleaner API.Testing strategy:
6 unit tests covering
runCoroutineSync:TimeoutErrorwhen timeout is exceededRuntimeErrorwhen the event loop is not runningRun with:
rununittests.bat -k test_asyncioEventLoopKnown issues with pull request:
The module is marked as private (underscore prefix) intentionally. The API is stable for current internal use, but is not part of NVDA's public API so add-on developers should not depend on it.
Code Review Checklist: